//Name: Cao Dung Anh
//Class: 11CTT
//Sid: 1151003

#include <iostream>
using namespace std;

#include "UserInfo.h"
#include "UserList.h"
#include "BookInfo.h"
#include "BookList.h"
#include "Library.h"
#include "BookBorrowing.h"

int main()
{
	
	UserList a;
	BookList b;
	BookInfo d[1000];
	Library c;
	char cChoice[1000];
	int choice;

	do 
	{
		cout << "1. Login\n"
			<< "2. Register\n"
			<< "3. Exit\n";
		
		do 
		{
			cout << "Choose: ";
			cin.getline(cChoice,sizeof(cChoice)); // input to a char type variable to check
			if (a.isNumber(cChoice)) // if the input char is a number then it's valid
				choice = a.convertStringtoNum(cChoice);
			else
				choice = 0; // if not, it's invalid and the users have to input again.

			switch (choice)
			{
			case 1:
				char username[100];
				strcpy(username,c.login());
				if (username != NULL)
				{
					a.loadUserList();
					if (a.checkUserType(username) == 1)
					{
						c.beAdmin(username);//The role for administrators
						choice = -1;
					}
					else if (a.checkUserType(username) == 2)
					{
						c.beLibrarian(username);//the role for librarians
						choice = -1;
					}
					else if (a.checkUserType(username) == 3)
					{
						c.beReader(username);// the role for readers
						choice = -1;
					}
					else
					{
						cout << "This case not suppose to be exist\n";
					}
				}
				break;
			case 2:
				a.addUsertoFile(3);
				choice = -1;
				break;
			case 3:
				cout << "\nGood bye!!!\n";
				return 0;
				break;
			default:
				choice = 0;
				cout << "Invalid option, you have to choose again\n";
			}
			cout <<endl;
		} while (choice == 0);
	} while (choice == -1);
	
	
	//cout << "Good bye\n";
}